﻿<%@ WebHandler Language="C#" Class="wxMiniProgramLogin" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Net;
using Newtonsoft.Json.Linq;
using System.Collections;

public class wxMiniProgramLogin : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";


            
        string openid = context.Request.Headers["X-ACCESS-USER"];//Header中的token

        if (string.IsNullOrEmpty(openid))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }

        string type = HttpContext.Current.Request.QueryString["type"];
        string page = HttpContext.Current.Request.QueryString["page"];
        string numb = HttpContext.Current.Request.QueryString["numb"];


        using (Entities bll = new Entities())
        {

            var dd = bll.S_Order.Where(p => p.UGUID == openid && p.OParentId == 0 && p.OState > -2);
            if (type == "all")
            {

            };
            if (type == "nopay")
            {
                dd = dd.Where(x => x.OState == -1);
            };
            if (type == "nosend")
            {
                     dd = dd.Where(x => x.OState == 0);
            };
            if (type == "noget")
            {
                      dd = dd.Where(x => x.OState ==1);
            };
            if (type == "nocomment")
            {
                     dd = dd.Where(x => x.OState ==2);
            };

            dd=dd.OrderByDescending(x=>x.OrderID);//全部.ToList();



            ArrayList listjson = new ArrayList();
            foreach (var x in dd)
            {
                var mnews = bll.S_Order.Where(p => p.OParentId == x.OrderID || p.OrderID == x.OrderID).ToList();//全部

                ArrayList lisitem = new ArrayList();
                foreach (var xx in mnews)
                {
                    lisitem.Add(new
                    {
                        id = xx.OrderID,
                        goods_image = xx.SPImgUrl,
                        goods_title = xx.SPName,
                        goods_price = xx.STruePrice,
                        pay_price=xx.STruePrice,
                        goods_num=xx.ONumber
                    });

                }


                listjson.Add(new
                {
                    order_sn = x.OOrderNumber,
                    status = x.OState,
                    total_fee = x.OFinalPrice,
                   
                    goods_amount=x.OFinalPrice,
                    goods_original_amount=x.OFinalPrice,
                    status_desc="等待买家付款",
                    pay_fee=x.OLastPrice,
                    status_name="待付款",
                    total_amount=_rky.getSordeSumMoney(x.OrderID.ToString()),
                    id= x.OrderID,
                    OrderID = x.OrderID,
                    item = lisitem,
                    btns = new string[] { "cancel", "pay","delete" }
                });

            };
            var data = new
            {
                total = dd.Count(),
                per_page = 10,
                current_page = 1,
                last_page = 1,
                data =listjson

            };


            var code = 1;
            var msg = "商品详情";
            var time = DateTime.Now;



            context.Response.Write(JsonConvert.SerializeObject(new { code,msg,time, data}));

        }

        HttpContext.Current.Response.End();

    }



    public bool IsReusable {
        get {
            return false;
        }
    }

}